package xyz.weizhi.controller;


import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import xyz.weizhi.pojo.User;

import java.util.Date;

/**
 * @Author milian
 * @Date 2021/9/12 0012 21:12
 */
@Controller
public class UserController {
    @RequestMapping(value = "/user",method = RequestMethod.POST)
    @ResponseBody
    public String save(@RequestParam(name = "username") String name, String password){
        System.out.println("username:"+name+"====>password:"+password);
        return "{'username':'weizhi'}";
    }

    @RequestMapping(value = "/users/{id}",method = RequestMethod.DELETE)
    @ResponseBody
    public String deleteUser(@PathVariable Integer id){
        System.out.println("user delete"+id);
        return "{'username':'weizhi'}";
    }

    @RequestMapping("/save/pojo2")
    @ResponseBody
    public String savePojo2(User user){
        System.out.println("username:"+user.getUsername()+"====>password:"+user.getPassword()+"=====>Address:"+user.getAddress());

        return "{'username':'weizhi'}";
    }
    @RequestMapping("/save/pojo3")
    @ResponseBody
    public String savePojo3(@RequestBody User user){
        System.out.println("username:"+user.getUsername()+"====>password:"+user.getPassword()+"=====>Address:"+user.getAddress());
        System.out.println(user);
        return "{'username':'weizhi'}";
    }
    @RequestMapping("/save/pojo4")
    @ResponseBody
    public String savePojo4(Date date,
                           @DateTimeFormat(pattern = "yyyy-MM-dd") Date date1){
        System.out.println("date=====>" +date);
        System.out.println("date=====>" +date1);
        return "{'username':'weizhi'}";
    }

    @RequestMapping("/save/pojo5")
    @ResponseBody
    public String savePojo5(Date date,
                            @DateTimeFormat(pattern="yyyy-MM-dd") Date date1,
                            @DateTimeFormat(pattern="yyyy/MM/dd HH:mm:ss") Date date2){
        System.out.println("参数传递 date ==> "+date);
        System.out.println("参数传递 date1(yyyy-MM-dd) ==> "+date1);
        System.out.println("参数传递 date2(yyyy/MM/dd HH:mm:ss) ==> "+date2);
        return "{'module':'data param'}";
    }
}
